<template>
  <div>
    <FilterTable ref="table" :columns="columns" :fetchapi="fetchApi" :params="fetchParams" :datakey="'rows'" :height="200" :onColumnsChange="columns => (this.columns = columns)">
      <template slot="controls" slot-scope="props">
        <el-button size="small" type="primary" icon="el-icon-plus" @click="visible = true">新增</el-button>
        <!-- <el-button size="small">导出</el-button> -->
      </template>
    </FilterTable>
  </div>
</template>

<script>
import { mapState } from 'vuex';
import { dictionary } from '@/utils/dictMixin';
import mainGroup from './mainGroup';
import { getOrders } from '@/api/vehicle/order/maintain';

export default {
  name: 'Ordermanage',
  mixins: [dictionary],
  data() {
    this.BaseTable = null;
    return {
      fetchApi: getOrders,
      dialogTitle: '',
      fetchParams: { xhrAbort: true },
      columns: this.createTableColumns()
    };
  },
  mounted() {
    this.BaseTable = this.$refs.table.$refs.pageTable;
  },
  methods: {
    createTableColumns() {
      return [
        {
          title: '操作',
          dataIndex: 'column-action',
          width: 200,
          fixed: 'left',
          render: props => {
            return (
              <div>
                <el-button size="mini" type="text" disabled={this.isEdit(props.row)}>
                  编辑
                </el-button>
                <el-divider direction="vertical" />
              </div>
            );
          }
        },
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '主分类代码',
          dataIndex: 'MAIN_GROUP_CODE',
          width: 150,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '主分类名称',
          dataIndex: 'MAIN_GROUP_NAME',
          width: 150,
          sorter: true,
          filter: true,
          filterType: 'input'
        },

        {
          title: '数据来源',
          dataIndex: 'DOWN_TAG',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('1045'),
          render: props => {
            return <span>{this.createDictText(props.row.ORDER_TYPE, '1045')}</span>;
          }
        }
      ];
    },
    createTopFilterList() {
      return [
        {
          type: 'INPUT',
          label: '主分类代码',
          fieldName: 'mainGroupCode',
          placeholder: '附加项目代码...'
        },
        {
          type: 'INPUT',
          label: '主分类名称',
          fieldName: 'mainGroupName',
          placeholder: '附加项目名称...'
        },
        {
          type: 'SELECT',
          label: '数据来源',
          fieldName: 'downTag',
          placeholder: '请选择',
          itemList: this.createDictList(1045)
        }
      ];
    },
    isEdit(row) {
      if ((row.ORDER_STATUS === 40081005 || row.ORDER_STATUS === 40081001) && row.SPECIAL_STATUS !== 40091002 && row.ORDER_TYPE !== 40051001) {
        return false;
      } else {
        return true;
      }
    },
    isCommit(row) {
      if ((row.ORDER_STATUS === 40081005 || row.ORDER_STATUS === 40081001) && (row.ORDER_TYPE !== 40051005 || (row.ORDER_TYPE === 40051005 && row.SPECIAL_STATUS === 40091005))) {
        return false;
      } else {
        return true;
      }
    },
    isApproved(row) {
      if (row.SPECIAL_STATUS === 40091003 || row.SPECIAL_STATUS === 40091001 || row.SPECIAL_STATUS === 40091005 || row.SPECIAL_STATUS === 40091006) {
        return false;
      } else {
        return true;
      }
    },
    changeHandle(val) {
      this.fetchParams = Object.assign({}, val, { xhrAbort: false });
    },
    collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    },
    closeHandler(val) {
      this.visible = val;
    }
  }
};
</script>
